package com.hotel.controller.user;

import com.hotel.dto.ShoppingCarDTO;
import com.hotel.result.Result;
import com.hotel.service.ShoppingService;
import com.hotel.vo.ShoppingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shopping")
@Slf4j
@Api(tags = "购物车接口")
public class ShoppingController {

    @Autowired
    private ShoppingService shoppingService;

    /**
     * 获取购物车列表
     */
    @ApiOperation("获取购物车列表")
    @GetMapping("/list")
    public Result<List<ShoppingVo>> list(){
        List<ShoppingVo> shoppingVO = shoppingService.getAll();
        return Result.success(shoppingVO);
    }
    /**
     *添加商品到购物车
     *  */
    @ApiOperation("添加商品到购物车")
    @PostMapping("/add")
    public Result<List<ShoppingVo>> add(@ApiParam ("添加商品到购物车") @RequestBody ShoppingCarDTO shoppingCarDTO)
        {
        List<ShoppingVo> shoppingVO = shoppingService.add(shoppingCarDTO);
        return Result.success(shoppingVO);
    }
    /**
     * 减少购物车中的商品
     */
    @ApiOperation("删除购物车中的商品")
    @PostMapping("/sub")
    public Result<List<ShoppingVo>> delete(@ApiParam ("减少购物车中的商品") @RequestBody ShoppingCarDTO shoppingCarDTO)
    {
        List<ShoppingVo> shoppingVO = shoppingService.sub(shoppingCarDTO);
        return Result.success(shoppingVO);
    }
    /**
     * 清空购物车中的所有商品
     */
    @ApiOperation("删除购物车中的所有商品")
    @GetMapping("/deleteAll/{id}")
    public Result<List<ShoppingVo>> deleteAll(@PathVariable Long id)
    {
        List<ShoppingVo> shoppingVO = shoppingService.deleteAll(id);
        return Result.success(shoppingVO);
    }
}
